package com.sanjiahantang.ythshopping.adapter.home;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.sanjiahantang.ythshopping.R;
import com.sanjiahantang.ythshopping.activity.GoodsFilterActivity;
import com.sanjiahantang.ythshopping.config.ConfigValue;
import com.sanjiahantang.ythshopping.model.Brands;
import com.squareup.picasso.Picasso;

import java.util.List;


/**
 * Created by ZHY_9 on 2017/6/21.
 */

public class BrandListMoreAdapter extends RecyclerView.Adapter<BrandListMoreAdapter.BrandsListHolder> {

    private Context context;
    private List<Brands> datas;

    public BrandListMoreAdapter(Context context, List<Brands> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public BrandsListHolder onCreateViewHolder(ViewGroup parent, final int viewType) {
        View view = LayoutInflater.from(context)
                .inflate(R.layout.item_brand_list, parent, false);
        BrandsListHolder holder = new BrandsListHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(BrandsListHolder holder, final int position) {
        Picasso.with(context).load(ConfigValue.IMG_IP + datas.get(position).getBrand_logo()).into(holder.img);
        holder.view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, GoodsFilterActivity.class);
                Bundle bundle = new Bundle();
                bundle.putInt("brand_id", datas.get(position).getBrand_id());
                bundle.putBoolean("home_brand", true);
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    class BrandsListHolder extends RecyclerView.ViewHolder{

        private ImageView img;
        private View view;

        public BrandsListHolder(View itemView) {
            super(itemView);
            view = itemView;
            img = (ImageView) itemView.findViewById(R.id.brand_img);
        }
    }
}
